<%@page import="com.dfhc.util.CryptoHelper"%>
<%@page import="com.dfhc.bus.carposition.ICarPositionConstants" %>
<%@page import="org.quickbundle.tools.helper.RmJspHelper" %>
<%@page import="org.quickbundle.project.RmGlobalReference" %>
<%@page import="com.dfhc.ISystemConstant" %>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>

<!DOCTYPE html>
<html lang="en">
	<head>
	
	<!-- 全局js 和css包 -->
	<%@ include file="/jsp/include/web/jqGrid/global.jsp" %>
	<meta charset="utf-8" />
	<title>流程列表</title>

	<meta name="description" content="Dynamic tables and grids using jqGrid plugin" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<script type="text/javascript">
			//导入
		    function importModel(){
		    		
		    		
		    		
		    }
	</script>
</head>
<body>
<c:if test="${not empty message}">
	<div class="ui-widget">
			<div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;"> 
				<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
				<strong>提示：</strong>${message}</p>
			</div>
		</div>
	</c:if>	
	
 <!--begin  导入 -->
	
  <div class="ui-widget-overlay ui_out_tan" ></div>

  <div class="ui-widget ui-widget-content ui-corner-all ui-jqdialog jqmID1 ui_inner_tan" id="add_form" dir="ltr" tabindex="-1" role="dialog" aria-labelledby="edithdgrid-table" aria-hidden="false" >
  <div class="ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"  style="cursor: move;">
	   <span class="ui-jqdialog-title" style="float: left;">导入流程</span>
	   <a href="javascript:void(0)" class="cancel ui-jqdialog-titlebar-close ui-corner-all" style="right: 0.3em;">
	    <span class="ui-icon ui-icon-closethick"></span>
	   </a>
   </div>
   <div class="ui-jqdialog-content ui-widget-content" id="editcntgrid-table"><div>
   <div class="modal-body">
   <form name="insertForm" id="insertForm" class="FormGrid ui_inner_form" action="<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/model/create")%>?jsguid="+__global_guid target="_blank" method="post" >
   <input id="key" name="key" type="hidden" />   
   <div class="control-group">
			 <div class="controls">
							
							<div class="input-prepend">
							
							<span class="add-on">支持文件格式：zip、bar、bpmn、bpmn20.xml</span><input class="m-wrap" name="file" id="file"  type="file"  />
							
							</div>
						

     	                 </div>
                         </div>
     </form>
     </div>
     
     <div class="EditTable operate_div" >
       <a href="javascript:void(0)" id="sData" class="fm-button ui-state-default ui-corner-all fm-button-icon-left" onclick="javascript:uploadFile('<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/model/filedeploy")%>','file','<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/model/listprocedef")%>');">
       <i class="icon-ok"></i>
               提交</a>
       <a href="javascript:void(0)" id="cData" class="cancel fm-button ui-state-default ui-corner-all fm-button-icon-left">
      <i class="icon-remove"></i> 
              取消</a>
     </div>
   
     </div></div><div class="jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se"></div></div>
	
	<!-- end 导入-->
	
	<!-- begin 查询 -->
    
    <div class="ui-widget ui-widget-content ui-corner-all ui-jqdialog jqmID1 ui_inner_tan" id="portlet-config-query" dir="ltr" tabindex="-1" role="dialog" aria-labelledby="edithdgrid-table" aria-hidden="false" >
      <div class="ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"  style="cursor: move;">
	   <span class="ui-jqdialog-title" style="float: left;">查询</span>
	   <a href="javascript:void(0)" class="cancel ui-jqdialog-titlebar-close ui-corner-all" style="right: 0.3em;">
	    <span class="ui-icon ui-icon-closethick"></span>
	   </a>
   </div>
   <div class="ui-jqdialog-content ui-widget-content" id="editcntgrid-table"><div>
   <div class="modal-body">
   <form name="form" id="form" class="FormGrid ui_inner_form" method="post" >   
           <div class="control-group">
							<div class="controls">
			
							<div class="input-prepend">
							  <span class="add-on">名称</span><input class="m-wrap" name="name"  type="text"  />
							</div>

							</div>
			 </div>
     
     </form>
     </div>
     
     <div class="EditTable operate_div" >
       <a href="javascript:void(0)" id="sData" class="fm-button ui-state-default ui-corner-all fm-button-icon-left" onclick="javascript:searchShi($(form).serialize());">
       <i class="icon-search"></i>
           查询</a>
       <a href="javascript:void(0)" id="cData" class="cancel fm-button ui-state-default ui-corner-all fm-button-icon-left">
      <i class="icon-remove"></i> 
              取消</a>
     </div>
   
     </div></div>
     
     </div>
     
    
    
    <!-- end 查询 -->

    <!-- begin 删除 -->
      <div class="ui-widget ui-widget-content ui-corner-all ui-jqdialog jqmID1 ui_inner_tan" id="portlet-config-delete" dir="ltr" tabindex="-1" role="dialog" aria-labelledby="edithdgrid-table" aria-hidden="false" >
      <div class="ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"  style="cursor: move;">
	   <span class="ui-jqdialog-title" style="float: left;">删除选中的数据</span>
	   <a href="javascript:void(0)" class="cancel ui-jqdialog-titlebar-close ui-corner-all" style="right: 0.3em;">
	    <span class="ui-icon ui-icon-closethick"></span>
	   </a>
   </div>
   <div class="ui-jqdialog-content ui-widget-content" id="editcntgrid-table"><div>
   <div class="modal-body">
   <form name="deleteForm" id="deleteForm" class="FormGrid ui_inner_form"  method="post"  >
   
           <div class="control-group">
				<span>确认删除选中的数据？</span>
			 </div>
     
     </form>
     </div>
     
     <div class="EditTable operate_div" >
       <a href="javascript:void(0)" id="sData" class="fm-button ui-state-default ui-corner-all fm-button-icon-left btn-danger" onclick="javascript:_deleteDeployment()">
       <i class="icon-trash"></i>
           确认删除</a>
       <a href="javascript:void(0)" id="cData" class="cancel fm-button ui-state-default ui-corner-all fm-button-icon-left">
      <i class="icon-remove"></i> 
              取消</a>
     </div>
   
     </div></div><div class="jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se"></div></div>
     
    <!-- end 删除 -->
	
	   <!-- begin  右上角 -->
	   
   		<%@ include file="/jsp/include/web/jqGrid/rightTop.jsp"%>
	
		
	   <!-- end 右上角 -->

		

					<div class="page-content">
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->

								<table id="grid-table"></table>

								<div id="grid-pager"></div>

								<script type="text/javascript">
									var $path_base = "/";//this will be used in gritter alerts containing images
								</script>

								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->


		<script type="text/javascript">
			//var grid_data = ${grid_data};	
		
			jQuery(function($) {
				var grid_selector = "#grid-table";
				var pager_selector = "#grid-pager";
				jQuery(grid_selector).jqGrid({
					//direction: "rtl",
					
					url: getRootPath()+'<%=CryptoHelper.encryptUrl(request,"/model/ajaxListprocedef")%>?jsguid='+__global_guid,
					datatype: "json",
				    mtype: 'POST',  
					height: '100%',
					colNames:[
'id',					
'部署ID'
,'名称'
,'KEY'
,'版本号'
,'XML'
,'图片'
,'是否挂起'
],
					colModel:[/* 列表的排列顺序不要轻易改变，改变前注意根据索引获取 值的方法 */
			{name:'id',index:'id',width:90, editable:true,hidedlg:true,hidden:true},					
			{name:'deploymentId',index:'deploymentId', width:90,editable: true,editoptions:{size:"20",maxLength:"19"}},
			{name:'name',index:'name', width:90,editable: true,editoptions:{size:"20",maxLength:"9"}},
			{name:'key',index:'key', width:90,editable: true,editoptions:{size:"20",maxLength:"9"}},
			{name:'version',index:'version', width:90,editable: true,editoptions:{size:"20",maxLength:"9"}},
			{name:'resourceName',index:'resourceName',width:130, editable:true,formatter:formatLink},
			{name:'diagramResourceName',index:'diagramResourceName',width:130, editable:true,formatter:formatLink},
			{name:'suspended',index:'suspended', width:100,editable: true,editoptions:{size:"20",maxLength:"19"},formatter:formatProcessStatus}
					], 
			        shrinkToFit:false,//不随列数量改变列宽度
					viewrecords : true,
					rownumbers:true,
					rowNum:15,
					rowList:[15,30],
					pager : pager_selector,
					sortname : 'id',//初始化的时候排序的字段
					sortorder : "desc",//排序方式,可选desc,asc
					altRows: true,
					//toppager: true,
					
					multiselect: true,
					//multikey: "ctrlKey",
			        multiboxonly: true,
			
					loadComplete : function() {
						var table = this;
				        //调整表头checkbox位置
						$('#cb_grid-table').css("margin-top","-6px");
						$('#cb_grid-table').css("margin-left","4px");

						setTimeout(function(){
							
							
							updateActionIcons(table);
							updatePagerIcons(table);
							enableTooltips(table);
						}, 0);
					},
			
					editurl: getRootPath()+'/carposition/update',//nothing is saved
					caption: "流程定义列表展示",
					autowidth: true
			
				});
				
				//enable search/filter toolbar
				//jQuery(grid_selector).jqGrid('filterToolbar',{defaultSearch:true,stringResult:true})
			
			
				//navButtons
				jQuery(grid_selector).jqGrid('navGrid',pager_selector,
					{ 	//navbar options
						edit: false,
						editicon : 'icon-pencil blue',
						add: false,
						addicon : 'icon-plus-sign purple',
						del: false,
						delicon : 'icon-trash red',
						search: false,
						searchicon : 'icon-search orange',
						refresh: false,
						refreshicon : 'icon-refresh green',
						view: false,
						viewicon : 'icon-zoom-in grey',
					
					}
				)
				
				//导入
			   jQuery(grid_selector) .navButtonAdd(pager_selector,
					{ caption:"",title:"导入", buttonicon:"icon-resize-small blue",
				      onClickButton: importShow, position:"last" }) ;
			
			   //激活/挂起
			   jQuery(grid_selector) .navButtonAdd(pager_selector,
					{ caption:"",title:"激活/挂起", buttonicon:"icon-eject blue",
				      onClickButton:activeSuspend, 
				      position:"last" }) ;
			   //删除
			   jQuery(grid_selector) .navButtonAdd(pager_selector,
					{ caption:"",title:"删除", buttonicon:"icon-trash red",
				      onClickButton:deleteShow , 
				      position:"last" }) ;
				
			   //查询
			   jQuery(grid_selector) .navButtonAdd(pager_selector,
					{ caption:"",title:"查询", buttonicon:"icon-search orange",
				      onClickButton:search_div , 
				      position:"last" }) ;
			  //转换为Model
			   jQuery(grid_selector) .navButtonAdd(pager_selector,
					{ caption:"",title:"转换为Model",
				        onClickButton:to_convertToModel , buttonicon:"icon-random red",
					position:"last" }) ;				
			  //启动实例
			  jQuery(grid_selector) .navButtonAdd(pager_selector,
					{ caption:"",title:"启动实例" ,buttonicon:"icon-play blue",
				        onClickButton:to_start , 
					position:"last" }) ;					
							
			  //激活/挂起
			  function activeSuspend(){
			    	var checkedLen= $(".cbox:checked").length;
			    	if(checkedLen==0){
			    		alert("请至少选择一条数据！");
			    		return false;
			    	}
			    	if(checkedLen>1){
			    		alert("最多只能选择一条数据！");
			    		return false;
			    	}			
			    	var pointer=$(".cbox:checked").parents("tr");
                    var id=$(pointer).attr("id");	    	
                    submitUpdateAjax('<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/model/activeorsuspendProcessDefinition")%>','processDefinitionId='+id,'<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/model/listprocedef")%>');				    	
					}				
			  //导入弹出			     
			  function importShow(){			    	 
			    	 $(".ui_out_tan").show();
			    	 $("#add_form").show();
					 
				 }
			     
			  //转换为Model
			 function to_convertToModel(){
			    	 
			    	var checkedLen= $(".cbox:checked").length;
			    	if(checkedLen==0){
			    		
			    		alert("请至少选择一条数据！");
			    		return false;
			    	}
                    if(checkedLen>1){
			    		
			    		alert("最多只能选择一条数据！");
			    		return false;
			    	}
                    var pointer=$(".cbox:checked").parents("tr");
                    var id=$(pointer).attr("id");
                    submitUpdateAjax("<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/model/convert-to-model")%>","processDefinitionId="+id,"<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/model/listmodel")%>");
			     }
			     
			 //删除弹出
			 function deleteShow (){
		    	    var checkedLen= $(".cbox:checked").length;
			    	if(checkedLen==0){
			    		alert("请至少选择一条数据！");
			    		return false;
			    	}
			    	$(".ui_out_tan").show();
			        $("#portlet-config-delete").show(); 
			     }
			 //启动实例
			 function to_start(){
					var checkedLen= $(".cbox:checked").length;
			    	if(checkedLen==0){
			    		alert("请至少选择一条数据！");
			    		return false;
			    	}
                    if(checkedLen>1){
			    		
			    		alert("最多只能选择一条数据！");
			    		return false;
			    	}
                    var pointer=$(".cbox:checked").parents("tr");
                    var id=$(pointer).attr("id");
                    //submitUpdateAjax("<%=request.getContextPath()%>/model/start","processDefinitionId="+id,"<%=request.getContextPath()%>/model/listprocedef");
                    window.location.href="<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/generalbusinessprocess/view")%>?processDefinitionId="+id+"&<%=ISystemConstant.PREDEFINED_ERROR_JSP_URL%>=redirect:/model/listprocedef";                    
        		} 

                //查询层
			    function search_div(){
			    	 $(".ui_out_tan").show();
			    	 $("#portlet-config-query").show();
			     }
	   		     
				//翻译激活/挂起状态
				function formatProcessStatus(cellvalue, options, cell){
				    if(cellvalue==true){
				    	return "激活";
				    }else{
				    	return "挂起";
				    }						
					
				}	
				//格式化链接
				function formatLink(cellvalue, options, cell){
					return '<a target="_blank" href="<%=request.getContextPath()%>/model/read-resource?pdid='+cell.id+'&resourceName='+cellvalue+'">'+cellvalue+'</a>';
				}
				 	 		    
				//unlike navButtons icons, action icons in rows seem to be hard-coded
				//you can change them like this in here if you want
				function updateActionIcons(table) {
					/**
					var replacement = 
					{
						'ui-icon-pencil' : 'icon-pencil blue',
						'ui-icon-trash' : 'icon-trash red',
						'ui-icon-disk' : 'icon-ok green',
						'ui-icon-cancel' : 'icon-remove red'
					};
					$(table).find('.ui-pg-div span.ui-icon').each(function(){
						var icon = $(this);
						var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
						if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
					})
					*/
				}
				
				//replace icons with FontAwesome icons like above
				function updatePagerIcons(table) {
					var replacement = 
					{
						'ui-icon-seek-first' : 'icon-double-angle-left bigger-140',
						'ui-icon-seek-prev' : 'icon-angle-left bigger-140',
						'ui-icon-seek-next' : 'icon-angle-right bigger-140',
						'ui-icon-seek-end' : 'icon-double-angle-right bigger-140'
					};
					$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function(){
						var icon = $(this);
						var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
						
						if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
					})
				}
			
				function enableTooltips(table) {
					$('.navtable .ui-pg-button').tooltip({container:'body'});
					$(table).find('.ui-pg-div').tooltip({container:'body'});
				}
			
				//var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');
			
			
			});
			  //删除提交
			  function _deleteDeployment(){
			    	var checkedLen= $(".cbox:checked").length;
			    	if(checkedLen==0){
			    		alert("请至少选择一条数据！");
			    		return false;
			    	}
			    	if(checkedLen>1){
			    		alert("最多只能选择一条数据！");
			    		return false;
			    	}			
			       var pointer=$(".cbox:checked").parents("tr").find("td").eq(3);
                   var deploymentId=$(pointer).text();	
                   submitUpdateAjax("<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/model/deleteDeployment")%>?deploymentId="+deploymentId,"deploymentId=","<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/model/listprocedef")%>");
			}	
		</script>
	</body>
</html>
